import * as echarts from "echarts"
export const initChart = async (data1: any, xData: any) => {
  const divBox: any = document.getElementById("chartId")
  const myChart = echarts.init(divBox)
  const option = {
    tooltip:{show:true},
    xAxis: {
      type: 'category',
      boundaryGap:false,
      data: xData,
      axisLabel: {
        interval: 0
      }
    },
    yAxis: {
      type: 'value',
    },
    series: [
      {
        data: data1,
        type: 'line'
      }
    ]
  };
  
  myChart.setOption(option)

  // 监听窗口变化，响应图表
  window.addEventListener("resize", function () {
    if (myChart) {
      myChart.resize()
    }
  })

  return {
    resize: function () {
      myChart.resize()
    }
  }
}
